package com.sk.weichat.adapter;

import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.weichat.R;
import com.sk.weichat.bean.Friend;
import com.sk.weichat.helper.AvatarHelper;
import com.sk.weichat.util.AppUtils;

import java.util.List;
public class SearchContactAdapter extends BaseQuickAdapter<Friend, BaseViewHolder> {


    public String keyword;
    public SearchContactAdapter(List<Friend> data) {
        super(R.layout.item_search_contact, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, Friend item) {
        helper.addOnClickListener(R.id.layout_search_friend_item);
        helper.addOnClickListener(R.id.img_search_avatar);
        ImageView imgAvatar = helper.getView(R.id.img_search_avatar);
        TextView tv_search_remarkName = helper.getView(R.id.tv_search_remarkName);
        TextView tv_nike_name = helper.getView(R.id.tv_nike_name);

        //头像
        AvatarHelper.getInstance().displayAvatar("", item.getUserId(),imgAvatar, false);
        LinearLayout ll_nickname = helper.getView(R.id.ll_nickname);


        SpannableStringBuilder style = AppUtils.TextColorkeywordByBule(mContext,item.getNickName(),getKeyword());


        if (TextUtils.isEmpty(item.getRemarkName())){
            tv_search_remarkName.setText(style!=null?style:item.getNickName());
            ll_nickname.setVisibility(View.GONE);
        }else {
            ll_nickname.setVisibility(View.VISIBLE);
            SpannableStringBuilder style1 = AppUtils.TextColorkeywordByBule(mContext,item.getRemarkName(),getKeyword());
            tv_search_remarkName.setText(style1!=null?style1:item.getRemarkName());
            tv_nike_name.setText(style!=null?style:item.getNickName());
        }
    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }
}
